package com.AntiThesis.atmodtx2;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.lwjgl.util.glu.Project;

import javax.xml.bind.SchemaOutputResolver;
import java.util.HashMap;
import java.util.List;
import java.util.Random;


public class AntiThesisSkill2 {
    static Random random = new Random();
    HashMap<String, String> map = new HashMap();

    public void skill(String[] s) {
        for (int i = 0; i < s.length; i++) {

            map.put("value" + i, s[i]);
        }
        castskill(map);

    }



    private void castskill(HashMap<String, String> map) {
        double x = Double.parseDouble(map.get("value0"));
        double y = Double.parseDouble(map.get("value1"));
        double z = Double.parseDouble(map.get("value2"));
        double area = Double.parseDouble(map.get("value3"));
        String particleType = (map.get("value4"));
        World world = Minecraft.getMinecraft().player.world;
        double xzangle = Double.parseDouble(map.get("value5"));
        double xyzangle = Double.parseDouble(map.get("value6"));
        double xzanglestart = Double.parseDouble(map.get("value7"));
        double xyzanglestart = Double.parseDouble(map.get("value8"));
        double speed = Double.parseDouble(map.get("value9"));
        double amount = Double.parseDouble(map.get("value10"));
        String castuid = map.get("value11");
        String xadd = map.get("value12");
        String yadd = map.get("value13");
        String zadd = map.get("value14");
        Minecraft.getMinecraft().addScheduledTask(() -> {
            Entity player = null;
            List<Entity> loadedEntityList = Minecraft.getMinecraft().world.getLoadedEntityList();
            for (Entity entity : loadedEntityList) {
                if (entity.getUniqueID().toString().equals(castuid)) {
                    player = entity;
                }
            }

            Vec3d lookVec = player.getLookVec();
            Vec3d loc = new Vec3d(x, y, z);
            double add = 1 / amount;
            if (!xadd.equals("0") || !yadd.equals("0") || !zadd.equals("0")) {
                for (int degree = 0; degree < xzangle; degree += add) {
                    double radians = Math.toRadians(degree + xzanglestart);
                    double x1 = area * Math.cos(radians);
                    double z1 = area * Math.sin(radians);
                    world.spawnParticle(EnumParticleTypes.valueOf(particleType), x + x1, y, z + z1, Double.parseDouble(xadd) * speed, Double.parseDouble(yadd) * speed, Double.parseDouble(zadd) * speed);
                }
            } else {
                for (int degree = 0; degree < xzangle; degree += add) {
                    double radians = Math.toRadians(degree + xzanglestart);
                    double x1 = area * Math.cos(radians);
                    double z1 = area * Math.sin(radians);
                    world.spawnParticle(EnumParticleTypes.valueOf(particleType), x + x1, y, z + z1, random.nextDouble() * speed, random.nextDouble() * speed, random.nextDouble() * speed);
                }
            }
        });

    }

}